<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="提现账号" prop="cashingAccount">
        <el-input
          v-model="queryParams.cashingAccount"
          placeholder="请输入提现账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现类型" prop="cashingType">
        <el-select v-model="queryParams.cashingType" placeholder="请选择提现类型" clearable size="small">
          <el-option
            v-for="dict in cashingTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="真实姓名" prop="cashingFullname">
        <el-input
          v-model="queryParams.cashingFullname"
          placeholder="请输入提现人真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现状态" prop="cashingState">
        <el-select v-model="queryParams.cashingState" placeholder="请选择提现状态" clearable size="small">
          <el-option
            v-for="dict in cashingStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['app:cashing:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cashingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="50" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现人用户名" align="center" prop="userName" />
      <el-table-column label="提现账号" align="center" prop="cashingAccount" />
      <el-table-column label="提现类型" align="center" prop="cashingType" :formatter="cashingTypeFormat" />
      <el-table-column label="提现人真实姓名" align="center" prop="cashingFullname" />
      <el-table-column label="提现金额" align="center" prop="cashingMoney" />
      <el-table-column label="提现手续费" align="center" prop="cashingPoundage" />
      <el-table-column label="实际打款金额" align="center" prop="realMoney" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现状态" align="center" prop="cashingState" :formatter="cashingStateFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.cashingState == '1'"
            icon="el-icon-s-check"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['app:cashing:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.cashingState != '1'"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['app:cashing:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改APP用户提现记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="提现人用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="提现人用户名" disabled />
        </el-form-item>
        <el-form-item label="提现类型" prop="cashingType">
          <el-select v-model="form.cashingType" placeholder="请选择提现类型" disabled>
            <el-option
              v-for="dict in cashingTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属银行" prop="bankName" v-if="form.cashingType == '2'">
          <el-input v-model="form.bankName" placeholder="暂无" disabled />
        </el-form-item>
        <el-form-item label="提现账号" prop="cashingAccount">
          <el-input v-model="form.cashingAccount" placeholder="请输入提现账号" disabled />
        </el-form-item>
        <el-form-item label="提现人姓名" prop="cashingFullname">
          <el-input v-model="form.cashingFullname" placeholder="请输入提现人真实姓名" disabled />
        </el-form-item>
        <el-form-item label="提现金额" prop="cashingMoney">
          <el-input v-model="form.cashingMoney" placeholder="请输入提现金额" disabled />
        </el-form-item>
        <el-form-item label="提现手续费" prop="cashingPoundage">
          <el-input v-model="form.cashingPoundage" placeholder="请输入提现手续费" disabled />
        </el-form-item>
        <el-form-item label="审核意见">
          <el-radio-group v-model="form.cashingState" :disabled="disabledView">
            <el-radio label="2">同意</el-radio>
            <el-radio label="3">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驳回理由" prop="rejectReason" v-if="this.form.cashingState == '3'">
          <el-input v-model="form.rejectReason" type="textarea" placeholder="请输入驳回理由" :disabled="disabledView" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="disabledView" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!disabledView">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listCashing, getCashing, delCashing, addCashing, updateCashing, exportCashing } from "@/api/app/cashing";

  export default {
    name: "Cashing",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // APP用户提现记录表格数据
        cashingList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        disabledView: false,
        // 提现类型字典
        cashingTypeOptions: [],
        // 提现状态字典
        cashingStateOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          cashingAccount: null,
          cashingType: null,
          cashingFullname: null,
          cashingState: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          rejectReason: [
            { required: true, message: "驳回理由不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
      this.getDicts("app_withdrawal_type").then(response => {
        this.cashingTypeOptions = response.data;
      });
      this.getDicts("app_withdrawal_state").then(response => {
        this.cashingStateOptions = response.data;
      });
    },
    methods: {
      /** 查询APP用户提现记录列表 */
      getList() {
        this.loading = true;
        listCashing(this.queryParams).then(response => {
          this.cashingList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 提现类型字典翻译
      cashingTypeFormat(row, column) {
        return this.selectDictLabel(this.cashingTypeOptions, row.cashingType);
      },
      // 提现状态字典翻译
      cashingStateFormat(row, column) {
        return this.selectDictLabel(this.cashingStateOptions, row.cashingState);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userId: null,
          cashingAccount: null,
          cashingType: null,
          cashingFullname: null,
          cashingMoney: null,
          cashingPoundage:null,
          cashingState: null,
          passTime: null,
          rejectTime: null,
          rejectReason: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getCashing(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "APP用户提现审核";
          this.disabledView = false;
          this.form.cashingState = '2';
        });
      },
      /** 查看按钮操作 */
      handleView(row) {
        this.reset();
        const id = row.id || this.ids
        getCashing(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看APP用户提现";
          this.disabledView = true;
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCashing(this.form).then(response => {
                this.msgSuccess("审核成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除APP用户提现记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCashing(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有APP用户提现记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCashing(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
